const router = require("koa-router")();
const crypto = require('crypto')
const {
    CreateToken
} = require("../utils/");

router.prefix("/api");

router.get("/", async (ctx, next) => {
    let ct = new CreateToken()
    let token = await ct.updateToken()
    ctx.body = token
});
router.get("/checksign", async (ctx, next) => {
    const cusToken = "cMsjsPwyiWP5a"
    const {
        signature,
        timestamp,
        nonce,
        echostr
    } = ctx.query;
    const params = [cusToken, timestamp, nonce]
    params.sort()
    let sha1 = crypto.createHash('sha1')
    let sign = sha1.update(params.join()).digest('hex')
    console.log("signature =  sign",sign,signature);
    ctx.body = {
        sign,
        signature
    }
});
module.exports = router;